#!/usr/bin/env python3
# coding: utf-8

import math
from fractions import Fraction


def e_fact():
    e = Fraction(1)
    n = 0
    while True:
        yield e, n
        n += 1
        e += Fraction(1, math.factorial(n))

def e_def():
    e = Fraction(2)
    n = 1
    while True:
        yield e, n
        n += 1
        e = (Fraction(1) + Fraction(1, n)) ** n

if 0 and __name__ == "__main__":
    for prec in (1e-5, 1e-9):
        approx1 = 1.0
        n = 0
        while abs(approx1 - math.e) > prec and approx1 - math.e < 0:
            n += 1
            approx1 += 1 / math.factorial(n)
            print(n, approx1, '{:.25f}'.format(math.e - approx1), sep = '\t')
        print()

    for prec in (1e-1, 1e-2):
        approx2 = 2.0
        n = 1
        while abs(approx2 - math.e) > prec and approx2 - math.e < 0:
            n += 1
            approx2 = (1 + 1/n) ** n
            print(n, approx2, '{:.25f}'.format(math.e - approx2), sep = '\t')
        print()

if 0 and __name__ == "__main__":
    fact_approx = 1.0
    k = 1
    while k < int(1e+6):
        fact_approx += 1 / math.factorial(k)
        print('{:g}'.format(fact_approx - math.e))
        k += 1
    print(k)

if __name__ == "__main__":
    pass
